<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax修改页</title>
<script src="./static/js/jquery.min.js"></script>
</head>
<body>
<form id="myForm" name="myForm" action="employee/update" method="post">
		<input type="hidden" name="id" value=" " id="i" /><br />
		姓&nbsp;&nbsp;&nbsp;&nbsp;名:<input type="text" name="name" value=" " id="n"/><br />
		 年&nbsp;&nbsp;&nbsp;&nbsp;龄:<input type="text" name="age" value="  " id="a"/><br />
		薪&nbsp;&nbsp;&nbsp;&nbsp;资:<input type="text" name="salary"value=" " id="s"/> <br /> 
		入职日期：<input type="text" name="hireDate" value="  " id="h"></input>
        <br /> 
	<br /> <input type="button" value="提交" onclick="ajaxTest( )" />
	</form>
	<script>
       /* 获取url上的id的值 */
		var str = window.location.href;
		var num = str.indexOf("?");
		var id1 = str.substr(num + 1);
		var b = id1.indexOf("=");
		var id = id1.substr(b + 1);
        /*  在进入页面时就加载显示 */
		$(document).ready(function() {
			$.ajax({
				data : {
					'id' : id
				},
				type : "GET",
				dataType : 'json',
				url : "employee/toUpdate",
			/* 	error : function(em) {
					alert("error:" + em);
				}, */
				success : function(em) {
					/* alert("success:" + em); */
					$("#i").val(em.id);
					$("#n").val(em.name);
					$("#a").val(em.age);
					$("#s").val(em.salary);					
					var da = em.hireDate;
				   var da = new Date(da);
				    var year = da.getFullYear();
				    var month = da.getMonth()+1;
				    var day = da.getDate();
				    var hireDate= [year,month,day].join('-');				    
					$("#h").val(hireDate);
					
				}

			})
		})		
		function ajaxTest() {
			var id1 = $("#i").val();
			var name = $("#n").val();
			var age = $("#a").val();
			var salary = $("#s").val();
			var hireDate = $("#h").val();
			$.ajax({
				data : {
					 'id' : id1, 
					"name" : name,
					"age" : age,
					"salary" : salary,
					"hireDate" : hireDate 
				},
				type : "POST",
				dataType : 'json',
				url : "employee/update",
			/* 	error : function(data) {
					alert("error:"+data);
				}, */
				success : function(data) {
					window.location.href="http://localhost:8080/springMvcAndMybatisAjax/employee.html";				
				//alert("success:"+data);					
				}
			})
		} 
	</script>
</body>
</html>